{% extends 'base.html' %}

{% block title %}{{ user.username }} 的回答 - 知疑{% endblock %}

{% block content %}
<div class="row">
    <!-- 用户信息侧边栏 -->
    <div class="col-md-4">
        <div class="card mb-4">
            <div class="card-body text-center">
                <img src="{{ url_for('static', filename='img/' + user.avatar) }}" class="avatar-lg mb-3" alt="{{ user.username }}">
                <h4>{{ user.username }}</h4>
                <p class="text-muted">
                    <i class="fas fa-envelope me-1"></i>{{ user.email }}
                </p>
                <p class="text-muted">
                    <i class="fas fa-clock me-1"></i>加入于 {{ user.member_since.strftime('%Y-%m-%d') }}
                </p>
                {% if user.about_me %}
                <div class="mb-3">
                    <p>{{ user.about_me }}</p>
                </div>
                {% endif %}
                
                {% if current_user.is_authenticated and current_user.id == user.id %}
                <a href="{{ url_for('user.edit_profile') }}" class="btn btn-primary">
                    <i class="fas fa-edit me-1"></i>编辑资料
                </a>
                {% endif %}
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">活动统计</h5>
            </div>
            <div class="list-group list-group-flush">
                <div class="list-group-item d-flex justify-content-between align-items-center">
                    提问
                    <span class="badge bg-primary rounded-pill">{{ user.questions.count() }}</span>
                </div>
                <div class="list-group-item d-flex justify-content-between align-items-center">
                    回答
                    <span class="badge bg-primary rounded-pill">{{ user.answers.count() }}</span>
                </div>
                <div class="list-group-item d-flex justify-content-between align-items-center">
                    最后活跃
                    <span>{{ user.last_seen.strftime('%Y-%m-%d') }}</span>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 用户回答列表 -->
    <div class="col-md-8">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h4 class="mb-0">{{ user.username }} 的回答</h4>
                <div class="btn-group" role="group">
                    <a href="{{ url_for('user.profile', username=user.username) }}" class="btn btn-outline-primary">问题</a>
                    <a href="{{ url_for('user.user_answers', username=user.username) }}" class="btn btn-primary active">回答</a>
                </div>
            </div>
            <div class="list-group list-group-flush">
                {% for answer in answers.items %}
                <div class="list-group-item">
                    <h5 class="mb-2">
                        <a href="{{ url_for('question.detail', id=answer.question_id) }}" class="text-decoration-none">
                            {{ answer.question.title }}
                        </a>
                    </h5>
                    <div class="answer-content mb-2">
                        {{ answer.content|truncate(200) }}
                    </div>
                    <div class="answer-meta">
                        <span class="me-3">
                            <i class="fas fa-clock me-1"></i>{{ answer.create_time.strftime('%Y-%m-%d') }}
                        </span>
                        <span>
                            <i class="fas fa-thumbs-up me-1"></i>{{ answer.likes.count() }} 赞
                        </span>
                    </div>
                </div>
                {% else %}
                <div class="list-group-item text-center py-5">
                    <p class="text-muted mb-0">暂无回答</p>
                </div>
                {% endfor %}
            </div>
        </div>
        
        <!-- 分页 -->
        {% if answers.pages > 1 %}
        <nav aria-label="Page navigation" class="mt-4">
            <ul class="pagination justify-content-center">
                {% for p in answers.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
                    {% if p %}
                        {% if p == answers.page %}
                        <li class="page-item active">
                            <span class="page-link">{{ p }}</span>
                        </li>
                        {% else %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('user.user_answers', username=user.username, page=p) }}">{{ p }}</a>
                        </li>
                        {% endif %}
                    {% else %}
                    <li class="page-item disabled">
                        <span class="page-link">...</span>
                    </li>
                    {% endif %}
                {% endfor %}
            </ul>
        </nav>
        {% endif %}
    </div>
</div>
{% endblock %} 